$(function(){
	//加载数据
	loadDatas();
	
	//资产排序
	$("#score").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#score span"));
	});
	//奖券排序
	$("#prizes").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#prizes span"));
	});
	//充值排序
	$("#cz").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#cz span"));
	});
	//转账排序
	$("#ZengSongCha").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#ZengSongCha span"));
	});
	//当日输赢排序
	$("#TodayScore").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#TodayScore span"));
	});
	//总输赢排序
	$("#RealScore").click(function(){
		$("#sorts").val($(this).attr("id"));
		initSort($(this));
		changeSortClass($("#RealScore span"));
	});
});

//加载玩家列表数据
function loadDatas(s){
	
	if(s=="search"){
		$("#page").val("");
	}
	
	//页码
	var page = $("#page").val();
	//一页显示的条数
	var pageSize = 100;
	//状态
	var state = $("#state").val();
	
	//排序
	var sortkey = $("#sorts").val();
	var sortval = "";
	if(sortkey != ""){
		var val = $("#"+sortkey+" span").attr("class");
		if(val.indexOf("asc") != -1){
			sortval = "desc";
		}else if(val.indexOf("desc") != -1){
			sortval = "asc";
		}
	}
	$.ajax({
		type: "post",
		data: {"page":page, "pageSize":pageSize, "state":state, "sortKey":sortkey, "sortVal":sortval, "p":"noFuFei"},
		url: "../../../php/player/winLose/loadWinLoseControlList.php",
		beforeSend: function(){
			$("#databody").html('<tr><td colspan="16" align="center">数据正在加载中，请稍后~</td></tr>');
			$("#load").css("display","block");
		},
		success: function(msg){
//			console.log(msg);
			$("#load").css("display","none");
			
			//表格数据
			var datas = msg.records;
			var html = "";
			if(datas.length == 0){
				html += "<tr><td colspan='14' align='center'>没查询到符合条件的数据~</td></tr>";
			}else{
				for(var i = 0; i<datas.length; i++){
					//用户类型（
					//	1：银商 黄色 #FFFF00；
					//	2：大R 红色 #FF9393；
					//	3：小R 蓝色 #00ffff； 
					//	4：充值或买币蝗虫 绿色 #008000； 
					//	5：没充值或买币蝗虫 无色； 
					//	6：内部用户  玫红色 #6570fd）
					//	被控制的蝗虫玩家 #ffcc00
					//	资产大于200万的蝗虫玩家 #a800ff
					var userType = datas[i].userKind;//用户类型
					var score = datas[i].score;//资产
					var zbl = datas[i].cheatRate//作弊率
					if(userType == "1"){//银商
						html += "<tr style='background-color:yellow;'>";
					}else if(userType == "2"){//大R
						html += "<tr style='background-color:#FF9393;'>";
					}else if(userType == "3"){//小R
						html += "<tr style='background-color:#00ffff;'>";
					}else if(userType == "4"){//充值或买币蝗虫
						html += "<tr style='background-color:green;'>";
					}else if(userType == "5"){//没充值或买币蝗虫
						html += "<tr>";
					}else if(userType == "6"){//内部用户
						html += "<tr style='background-color: #6570fd;'>";
					}else if(userType == "5" && score >= 2000000){
						html += "<tr style='background-color:#a800ff;'>";
					}else if(userType == "5" && zbl != 0){
						html += "<tr style='background-color:#ffcc00;'>";
					}
					html += "<td><a style='font-weight:bold; color:black;' href='../playerInfo/playerDetailsInfo.php?gameId="+datas[i].gameId+"' title='查看玩家详情'>"+datas[i].nickName+"</a></td>";//用户昵称
					html += "<td>"+score+"</td>";//资产
					html += "<td>"+datas[i].prizes+"</td>";//奖券
					html += "<td>"+datas[i].zengSongCha+"</td>";//转账
					html += "<td>"+(datas[i].buyGoldFromBusMan==""?0:datas[i].sellGoldToBusMan)+"</td>";//赠送(银商)
					html += "<td>"+(datas[i].buyGoldFromBusMan==""?0:datas[i].receiveGoldFromFriend)+"</td>";//接收(玩家)
					html += "<td>"+(datas[i].buyGoldFromBusMan==""?0:datas[i].sendGoldToFriend)+"</td>";//赠送(玩家)
					//今日输赢
					var todayScore = datas[i].todayScore;
					if(todayScore < 0){
						html += "<td><font color='red'>"+todayScore+"</font></td>";
					}else{
						html += "<td>"+todayScore+"</td>";
					}
					//总输赢
					var realScore = datas[i].realScore;
					if(realScore < 0){
						html += "<td><font color='red'>"+realScore+"</font></td>";
					}else{
						html += "<td>"+realScore+"</td>";
					}
					html += "<td>"+(-zbl)+"</td>";//作弊率
					html += "<td>"+datas[i].limitScore+"</td>";//作弊限额
					html += "<td>"+datas[i].bloodScore+"</td>";//作弊状态
					var isOnline = datas[i].isOnline;//是否在线
					var offLineHour = datas[i].offLineHour;//离线时间
					
					//状态
					if(isOnline == "1" && offLineHour == "0"){
						html += "<td>在线</td>";
					}else{
						if(offLineHour % 24 == 0){
							html += "<td>"+(offLineHour / 24)+"天</td>";
						}else if(offLineHour > 24){
							html += "<td>"+parseInt(offLineHour / 24)+"天"+(offLineHour % 24)+"小时</td>";
						}else if(offLineHour < 24){
							html += "<td>"+offLineHour+"小时</td>";
						}
					}
					html += "<td><a href='javascript:void();' onclick='updateZBLWindow("+datas[i].userId+", "+datas[i].realScore+", "+datas[i].cheatRate+", "+datas[i].limitScore+", "+datas[i].bloodScore+")'>修改作弊</a></td>"
					html += "</tr>";
				}
			}
			$("#databody").html(html);
			
			//分页数据
			var pageInfo = msg.pageInfo;
			//总条数
			var allCount = pageInfo[0].count;
			$("#count").html(allCount);
			//总页数
			var allPage = Math.ceil(allCount/pageSize);
			if(allPage==0){
				allPage = 1;
			}
			//当前页码
			var now = pageInfo[0].page;
			
			$("#page").val(now);
			$("#nowPage").html(now);
			$("#allPage").html(allPage);
			$("#pageIpu").val("");
		}
	});
	
}
//查询所有
function searchAll(s){
	$("#load").css("display","block");
	
	$(":reset").click();
	
	loadDatas(s);
}
